Skip to content

Conversation

@GrumpyPigSkin
Copy link
Contributor

Added debug counter and test for slsr pass

fixes: #119770

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Dec 14, 2024

@llvm/pr-subscribers-llvm-transforms

Author: None (GrumpyPigSkin)

Changes

Added debug counter and test for slsr pass

fixes: #119770


Full diff: https://github.com/llvm/llvm-project/pull/119981.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp (+6-1)
  • (added) llvm/test/Other/debugcounter-slsr.ll (+30)
diff --git a/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
index 75585fcc802667..4d4bea3113cec7 100644
--- a/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
@@ -78,6 +78,7 @@
 #include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/DebugCounter.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Utils/Local.h"
@@ -93,6 +94,9 @@ using namespace PatternMatch;
 static const unsigned UnknownAddressSpace =
     std::numeric_limits<unsigned>::max();
 
+DEBUG_COUNTER(StraightLineStrengthReduceCounter, "slsr-counter",
+              "Controls whether rewriteCandidateWithBasis is executed.");
+
 namespace {
 
 class StraightLineStrengthReduceLegacyPass : public FunctionPass {
@@ -690,7 +694,8 @@ bool StraightLineStrengthReduce::runOnFunction(Function &F) {
   while (!Candidates.empty()) {
     const Candidate &C = Candidates.back();
     if (C.Basis != nullptr) {
-      rewriteCandidateWithBasis(C, *C.Basis);
+      if (DebugCounter::shouldExecute(StraightLineStrengthReduceCounter))
+        rewriteCandidateWithBasis(C, *C.Basis);
     }
     Candidates.pop_back();
   }
diff --git a/llvm/test/Other/debugcounter-slsr.ll b/llvm/test/Other/debugcounter-slsr.ll
new file mode 100644
index 00000000000000..facfc38f9e0c54
--- /dev/null
+++ b/llvm/test/Other/debugcounter-slsr.ll
@@ -0,0 +1,30 @@
+; REQUIRES: asserts
+; RUN: opt -passes=slsr,gvn -S -debug-counter=slsr-counter=1  < %s | FileCheck %s
+
+;; Test that, with debug counters on, we will skip the first slsr opportunity.
+
+define void @stride_is_2s(i32 %b, i32 %s) {
+; CHECK-LABEL: @stride_is_2s(
+; CHECK-NEXT:    %s2 = shl i32 %s, 1
+; CHECK-NEXT:    %t1 = add i32 %b, %s2
+; CHECK-NEXT:    call void @foo(i32 %t1)
+; CHECK-NEXT:    %t2 = add i32 %t1, %s2
+; CHECK-NEXT:    call void @foo(i32 %t2)
+; CHECK-NEXT:    %s6 = mul i32 %s, 6
+; CHECK-NEXT:    %t3 = add i32 %b, %s6
+; CHECK-NEXT:    call void @foo(i32 %t3)
+; CHECK-NEXT:    ret void
+;
+  %s2 = shl i32 %s, 1
+  %t1 = add i32 %b, %s2
+  call void @foo(i32 %t1)
+  %s4 = shl i32 %s, 2
+  %t2 = add i32 %b, %s4
+  call void @foo(i32 %t2)
+  %s6 = mul i32 %s, 6
+  %t3 = add i32 %b, %s6
+  call void @foo(i32 %t3)
+  ret void
+}
+
+declare void @foo(i32)
\ No newline at end of file

@GrumpyPigSkin
Copy link
Contributor Author

@justinfargnoli I can't add you to the reviewers for some reason so giving you a mention here. Let me know if I need to make any changes.

@justinfargnoli justinfargnoli changed the title [LLVM][SLSR] Add a debug counter #119770 [LLVM][SLSR] Add a debug counter Dec 16, 2024
Copy link
Contributor

@justinfargnoli justinfargnoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks great!

Leaving a few small "touch-up" comments.

@GrumpyPigSkin
Copy link
Contributor Author

@justinfargnoli, I have resolved all the comments. I had more of an issue adding a newline to the end of the file than anything 🙄 It Looks like the pull request has picked up the changes, let me know if there are any issues :)

Copy link
Contributor

@justinfargnoli justinfargnoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this @GrumpyPigSkin! LGTM :)

@justinfargnoli
Copy link
Contributor

justinfargnoli commented Dec 21, 2024

Merging on the author's behalf because they don't have commit access.

@justinfargnoli justinfargnoli merged commit f7ba2bd into llvm:main Dec 21, 2024
7 checks passed
@github-actions
Copy link

@GrumpyPigSkin Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 21, 2024

LLVM Buildbot has detected a new failure on builder publish-sphinx-docs running on as-worker-4 while building llvm at step 7 "Publish docs-clang-html".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/45/builds/7358

Here is the relevant piece of the build log for the reference
Step 7 (Publish docs-clang-html) failure: 'rsync -vrl ...' (failure)
kex_exchange_identification: Connection closed by remote host
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]

@justinfargnoli
Copy link
Contributor

LLVM Buildbot has detected a new failure on builder publish-sphinx-docs running on as-worker-4 while building llvm at step 7 "Publish docs-clang-html".

This looks like an infra failure and is likely unrelated to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LLVM][SLSR] Add a debug counter

4 participants